package com.yu.newsSys.service.impl;

import com.yu.newsSys.dao.AdminDao;
import com.yu.newsSys.service.AdminService;
import com.yu.newsSys.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;

public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public Result checkUserName(String username) {
        int count = adminDao.countByUserName(username);
        System.out.println("checkUserName from service running");
        if (count > 0) {
            return Result.ERROR();
        }
        return Result.OK();
    }

    @Override
    public Result save(String username, String password) {
        System.out.println("save from service running");
        int count = adminDao.save(username,password);
        if (count == 1) {
            return Result.OK();
        } else {
            return Result.ERROR();
        }
    }

    @Override
    public Result checkUser(String username, String password) {
        System.out.println("checkUser from service is running");
        int count = adminDao.checkUser(username,password);

        if (count == 1) {
            return Result.OK();
        } else {
            return Result.ERROR();
        }
    }
}
